package main

import (
    "fmt"
)

// 抽象产品接口
type Button interface {
    Render() string
    OnClick() string
    GetStyle() string
}

type Window interface {
    Show() string
    Close() string
    GetTheme() string
}

// 抽象工厂接口
type UIFactory interface {
    CreateButton(text string, config map[string]string) Button
    CreateWindow(title string, config map[string]string) Window
    GetThemeName() string
}

// 暗黑主题产品族
type DarkButton struct {
    Text   string
    Width  int
    Height int
}

func (d *DarkButton) Render() string {
    return fmt.Sprintf("渲染暗黑按钮: [%s] (%dx%d) 背景:#2D2D2D 文字:#FFFFFF", 
        d.Text, d.Width, d.Height)
}

func (d *DarkButton) OnClick() string {
    return fmt.Sprintf("暗黑按钮 '%s' 被点击，播放低沉音效", d.Text)
}

func (d *DarkButton) GetStyle() string {
    return "暗黑风格按钮"
}

type DarkWindow struct {
    Title  string
    Width  int
    Height int
}

func (d *DarkWindow) Show() string {
    return fmt.Sprintf("显示暗黑窗口: '%s' (%dx%d) 背景:#1E1E1E 边框:#404040", 
        d.Title, d.Width, d.Height)
}

func (d *DarkWindow) Close() string {
    return fmt.Sprintf("关闭暗黑窗口 '%s'，淡出动画", d.Title)
}

func (d *DarkWindow) GetTheme() string {
    return "暗黑主题窗口"
}

// 明亮主题产品族
type LightButton struct {
    Text   string
    Width  int
    Height int
}

func (l *LightButton) Render() string {
    return fmt.Sprintf("渲染明亮按钮: [%s] (%dx%d) 背景:#FFFFFF 文字:#333333", 
        l.Text, l.Width, l.Height)
}

func (l *LightButton) OnClick() string {
    return fmt.Sprintf("明亮按钮 '%s' 被点击，播放清脆音效", l.Text)
}

func (l *LightButton) GetStyle() string {
    return "明亮风格按钮"
}

type LightWindow struct {
    Title  string
    Width  int
    Height int
}

func (l *LightWindow) Show() string {
    return fmt.Sprintf("显示明亮窗口: '%s' (%dx%d) 背景:#FFFFFF 边框:#CCCCCC", 
        l.Title, l.Width, l.Height)
}

func (l *LightWindow) Close() string {
    return fmt.Sprintf("关闭明亮窗口 '%s'，滑动动画", l.Title)
}

func (l *LightWindow) GetTheme() string {
    return "明亮主题窗口"
}

// 具体工厂实现
type DarkThemeFactory struct{}

func (d *DarkThemeFactory) CreateButton(text string, config map[string]string) Button {
    width := 100
    height := 30
    
    if w, ok := config["width"]; ok {
        fmt.Sscanf(w, "%d", &width)
    }
    if h, ok := config["height"]; ok {
        fmt.Sscanf(h, "%d", &height)
    }
    
    return &DarkButton{
        Text:   text,
        Width:  width,
        Height: height,
    }
}

func (d *DarkThemeFactory) CreateWindow(title string, config map[string]string) Window {
    width := 800
    height := 600
    
    if w, ok := config["width"]; ok {
        fmt.Sscanf(w, "%d", &width)
    }
    if h, ok := config["height"]; ok {
        fmt.Sscanf(h, "%d", &height)
    }
    
    return &DarkWindow{
        Title:  title,
        Width:  width,
        Height: height,
    }
}

func (d *DarkThemeFactory) GetThemeName() string {
    return "暗黑主题"
}

type LightThemeFactory struct{}

func (l *LightThemeFactory) CreateButton(text string, config map[string]string) Button {
    width := 100
    height := 30
    
    if w, ok := config["width"]; ok {
        fmt.Sscanf(w, "%d", &width)
    }
    if h, ok := config["height"]; ok {
        fmt.Sscanf(h, "%d", &height)
    }
    
    return &LightButton{
        Text:   text,
        Width:  width,
        Height: height,
    }
}

func (l *LightThemeFactory) CreateWindow(title string, config map[string]string) Window {
    width := 800
    height := 600
    
    if w, ok := config["width"]; ok {
        fmt.Sscanf(w, "%d", &width)
    }
    if h, ok := config["height"]; ok {
        fmt.Sscanf(h, "%d", &height)
    }
    
    return &LightWindow{
        Title:  title,
        Width:  width,
        Height: height,
    }
}

func (l *LightThemeFactory) GetThemeName() string {
    return "明亮主题"
}

// UI管理器
type UIManager struct {
    factory UIFactory
}

func NewUIManager(factory UIFactory) *UIManager {
    return &UIManager{factory: factory}
}

func (u *UIManager) CreateGameInterface() {
    fmt.Printf("=== 使用 %s 创建游戏界面 ===\n", u.factory.GetThemeName())
    
    mainWindow := u.factory.CreateWindow("游戏主界面", map[string]string{
        "width":  "1024",
        "height": "768",
    })
    fmt.Println(mainWindow.Show())
    
    startButton := u.factory.CreateButton("开始游戏", map[string]string{
        "width":  "150",
        "height": "50",
    })
    fmt.Println(startButton.Render())
    
    settingsButton := u.factory.CreateButton("设置", map[string]string{
        "width":  "120",
        "height": "40",
    })
    fmt.Println(settingsButton.Render())
    
    fmt.Println()
}

// 使用演示
func main() {
    fmt.Println("=== UI主题工厂演示 ===")
    
    uiFactories := []UIFactory{
        &DarkThemeFactory{},
        &LightThemeFactory{},
    }
    
    for _, factory := range uiFactories {
        uiManager := NewUIManager(factory)
        uiManager.CreateGameInterface()
    }
}